package com.education.teach.mvp.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.education.teach.R;
import com.education.teach.mvp.contract.UserContract;
import com.education.teach.mvp.model.bean.LoginBean;
import com.education.teach.mvp.presenter.UserPresenter;
import com.education.teach.mvp.ui.activity.ClassWorksActivity;
import com.education.teach.mvp.ui.activity.MyWorksActivity;
import com.education.teach.mvp.ui.activity.SettingActivity;
import com.education.teach.mvp.ui.activity.TimetableActivity;
import com.education.teach.mvp.ui.activity.WrongCapActivity;
import com.education.teach.utils.DnCommonUtils;
import com.jess.arms.base.BaseFragment;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import butterknife.BindView;

import static com.jess.arms.utils.Preconditions.checkNotNull;

//import com.education.teach.di.component.DaggerUserComponent;


public class UserFragment extends BaseFragment<UserPresenter> implements UserContract.View {

    @BindView(R.id.right_iv)
    ImageView mRightIv;
    @BindView(R.id.tv_login)
    TextView mTvLogin;
    @BindView(R.id.tv_nick)
    TextView mTvNick;
    @BindView(R.id.tv_promote_tip)
    TextView mTvPromoteTip;
    @BindView(R.id.view_line)
    View mViewLine;
    @BindView(R.id.iv_browse_count)
    ImageView mIvBrowseCount;
    @BindView(R.id.tv_browse_count_hint)
    TextView mTvBrowseCountHint;
    @BindView(R.id.classwork)
    RelativeLayout mClasswork;
    @BindView(R.id.iv_promote_level)
    ImageView mIvPromoteLevel;
    @BindView(R.id.tv_promote_level)
    TextView mTvPromoteLevel;
    @BindView(R.id.rl_promote)
    RelativeLayout mRlPromote;
    @BindView(R.id.ll_middle_promo)
    LinearLayout mLlMiddlePromo;
    @BindView(R.id.rl_person_info)
    RelativeLayout mRlPersonInfo;
    @BindView(R.id.empty_text_view)
    TextView mEmptyTextView;
    @BindView(R.id.ll_feedback)
    LinearLayout mLlFeedback;
    @BindView(R.id.kc)
    LinearLayout mKc;
    @BindView(R.id.mine_set_i)
    LinearLayout mMineSetI;

    public static UserFragment newInstance() {
        UserFragment fragment = new UserFragment();
        return fragment;
    }

    @Override
    public void setupFragmentComponent(@NonNull AppComponent appComponent) {
//        DaggerUserComponent //如找不到该类,请编译一下项目
//                .builder()
//                .appComponent(appComponent)
//                .userModule(new UserModule(this))
//                .build()
//                .inject(this);
    }

    @Override
    public View initView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_user, container, false);
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        LoginBean mLoginBean = DnCommonUtils.getUserModel(getActivity());
        mTvNick.setText(mLoginBean.getResult().getYhmc());
        mTvPromoteTip.setText(mLoginBean.getResult().getDwmc());

        mClasswork.setOnClickListener(v -> launchActivity(new Intent(getActivity(), ClassWorksActivity.class)));

        mRlPromote.setOnClickListener(v -> launchActivity(new Intent(getActivity(), MyWorksActivity.class)));

        mKc.setOnClickListener(v -> launchActivity(new Intent(getActivity(), TimetableActivity.class)));

        mLlFeedback.setOnClickListener(v -> launchActivity(new Intent(getActivity(), WrongCapActivity.class)));

        mRightIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                launchActivity(new Intent(getActivity(), SettingActivity.class));
            }
        });
//        mLlFeedback.setOnClickListener(v -> Toast.makeText(this.getActivity(), "服务器异常 请稍后再试", Toast.LENGTH_SHORT).show());
    }

    @Override
    public void setData(@Nullable Object data) {

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {

    }

}
